package com.awphone.data;

import com.awphone.data.constant.EObjectType;
import com.awphone.data.constant.EntryHistoryConst;

import javax.persistence.*;
import java.util.Date;

/**
 * @author a_polyakov
 * Date: 03.03.13
 * Time: 22:35
 * История пользователя по входу в систему
 */
@Entity
@Table(schema = EntryHistoryConst.SCHEMA_NAME, name = EntryHistoryConst.TABLE_NAME)
public class EntryHistory extends AbstractObject {
    /**
     * Пользователь
     */
    private User user;
    /**
     * Время попытки входа
     */
    private Date created;
    /**
     * Попытка была удачной
     */
    private Boolean success;

    {
        setObjectType(EObjectType.ENTRY_HISTORY);
    }

    public EntryHistory() {
    }

    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = EntryHistoryConst.S_USER, nullable = false, updatable = false)
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Column(name = EntryHistoryConst.S_CREATED, nullable = false, unique = false, updatable = false)
    @Temporal(TemporalType.TIMESTAMP)
    public Date getCreated() {
        return created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    @Column(name = EntryHistoryConst.S_SUCCESS, nullable = false, updatable = false)
    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    @Override
    public void prePrePersist() {
        super.prePrePersist();
        this.created=new Date();
    }
}
